/**
 * PriceServiceImpl.java
 * 
 * Copyright@2015 OVT Inc. All rights reserved. 
 * 
 * Dec 30, 2015
 */
package com.ovt.doorbell.payment.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ovt.doorbell.payment.common.utils.DateTimeUtils;
import com.ovt.doorbell.payment.dao.constant.ResourceType;
import com.ovt.doorbell.payment.dao.vo.FullMemberProfile;
import com.ovt.doorbell.payment.dao.vo.MemberProfile;
import com.ovt.doorbell.payment.dao.vo.Order;
import com.ovt.doorbell.payment.service.exception.ServiceException;

/**
 * PriceServiceImpl
 * 
 * @Author zhi.liu
 * @Version 1.0
 * @See
 * @Since [OVT Cloud Platform]/[API] 1.0
 */
@Service
public class PriceServiceImpl implements PriceService
{

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ovt.doorbell.payment.service.PriceService#calculateOrderFee(com.ovt
     * .doorbell.payment.dao.vo.MemberProfile,
     * com.ovt.doorbell.payment.dao.vo.Order)
     */
    @Override
    public void calculateOrderFee(MemberProfile memberProfile, Order order)
            throws ServiceException
    {
        // TODO Auto-generated method stub

    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ovt.doorbell.payment.service.PriceService#calculateRefundFee(com.
     * ovt.doorbell.payment.dao.vo.FullMemberProfile)
     */
    @Override
    public void calculateRefundFee(FullMemberProfile fullMemberProfile)
            throws ServiceException
    {
        float spaceRefundFee = this.calculateRefundFee(fullMemberProfile, ResourceType.SPACE);
        float flowRefundFee = this.calculateRefundFee(fullMemberProfile, ResourceType.FLOW);

        fullMemberProfile.setRefundFee(spaceRefundFee + flowRefundFee);
    }
    
    public float calculateRefundFee(FullMemberProfile fullMemberProfile, ResourceType resourceType)
    {
        int remainDays = this.getRemainDays(fullMemberProfile);
        
        //TODO
        
        return 0.0f;
    }

    private int getRemainDays(FullMemberProfile fullMemberProfile)
    {
        Date expireDate = DateTimeUtils.parseDate(
                fullMemberProfile.getExpireTime(),
                DateTimeUtils.PATTERN_SQL_DATETIME_FULL);
        int remainDays = DateTimeUtils.dateDiff(new Date(), expireDate);
        
        return remainDays;
    }

}
